import java.util.*;
import java.io.*;
public class test {
    // 蓝桥杯 最近公共祖先LCA查询
    public class test9 {
        public static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        public static Read in = new Read();
        public static int n;
        public static int[][] fx;
        public static int[] dep;
        public static ArrayList<Integer>[] lists;
        public static int N = 100010;
        public static void main(String[] args) throws IOException{
            n = in.nextInt();
            fx = new int[N][20];
            dep = new int[N];
            lists = new ArrayList[N];
            for(int i = 0;i <= n;i++) {
                lists[i] = new ArrayList<>();
            }
            for(int i = 1;i < n;i++) {
                int a = in.nextInt();
                int b = in.nextInt();
                lists[a].add(b);
                lists[b].add(a);
            }
            dfs(1, 0);
            int q = in.nextInt();
            while(q-- > 0) {
                int a = in.nextInt();
                int b = in.nextInt();
                System.out.println(lca(a, b));
            }
        }
        public static void dfs(int node,int prev) {
            fx[node][0] = prev;
            for(int i = 1;i < 20;i++) {
                fx[node][i] = fx[fx[node][i-1]][i-1];
            }
            for(int a:lists[node]) {
                if(a == prev) continue;
                dep[a] = dep[node] + 1;
                dfs(a,node);
            }
        }
        public static int lca(int u,int v) {
            if(dep[u] < dep[v]) {
                int temp = u;
                u = v;
                v = temp;
            }
            for(int i = 19;i >= 0;i--) {
                if(dep[u] - dep[v] >= (1 << i)) {
                    u = fx[u][i];
                }
            }
            if(u == v) return u;
            for(int i = 19;i >= 0;i--) {
                if(fx[u][i] != fx[v][i]) {
                    u = fx[u][i];
                    v = fx[v][i];
                }
            }
            return fx[u][0];
        }
        // 蓝桥杯 小明的族谱
        public static int n;
        public static int[] dep;
        public static int[][] fx;
        public static ArrayList<Integer>[] lists;
        public static int N = 500050;
        public static void main(String[] args) throws IOException{
            n = in.nextInt();
            int q = in.nextInt();
            dep = new int[N];
            fx = new int[N][21];
            lists = new ArrayList[N];
            for(int i = 0;i <= n;i++) {
                lists[i] = new ArrayList<>();
            }
            for(int i = 1;i < n;i++) {
                int u = in.nextInt();
                int v = in.nextInt();
                lists[u].add(v);
                lists[v].add(u);
            }
            dfs(1, 0);
            while(q-- > 0) {
                int a = in.nextInt();
                int b = in.nextInt();
                System.out.println(lca(a, b));
            }
        }
        public static void dfs(int node,int prev) {
            fx[node][0] = prev;
            for(int i = 1;i <= 20;i++) {
                fx[node][i] = fx[fx[node][i-1]][i-1];
            }
            for(int a:lists[node]) {
                if(a == prev) continue;
                dep[a] = dep[node] + 1;
                dfs(a, node);
            }
        }
        public static int lca(int u,int v) {
            if(dep[u] < dep[v]) {
                int temp = u;
                u = v;
                v = temp;
            }
            for(int i = 20;i >= 0;i--) {
                if(dep[u] - dep[v] >= (1 << i)) {
                    u = fx[u][i];
                }
            }
            if(u == v) return u;
            for(int i = 20;i >= 0;i--) {
                if(fx[u][i] != fx[v][i]) {
                    u = fx[u][i];
                    v = fx[v][i];
                }
            }
            return fx[u][0];
        }
        class Read{
            StringTokenizer st = new StringTokenizer("");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String next() throws IOException{
                while(!st.hasMoreTokens()) {
                    st = new StringTokenizer(br.readLine());
                }
                return st.nextToken();
            }
            String nextLine() throws IOException{
                return br.readLine();
            }
            int nextInt() throws IOException{
                return Integer.parseInt(next());
            }
            long nextLong() throws IOException{
                return Long.parseLong(next());
            }
            double nextDouble() throws IOException{
                return Double.parseDouble(next());
            }
        }
    }

}


